package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Notice;
import com.hengxinguotong.zhihuichengjian.treeview.*;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/1/10
 */

public class NoticeListAdapter extends RecyclerAdapter<Notice, NoticeListAdapter.NoticeViewHolder> {


    public NoticeListAdapter(Context context, List<Notice> dataList) {
        super(context, dataList);
    }

    @Override
    public NoticeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_notice, null);
        return new NoticeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(NoticeViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class NoticeViewHolder extends RecyclerAdapter.BaseViewHolder<Notice>{
        @BindView(R.id.title_tv)
        HXTextView titleTv;
        @BindView(R.id.contacts_tv)
        HXTextView contactsTv;
        @BindView(R.id.head_portrait_img)
        ImageView headPortraitImg;
        @BindView(R.id.date_tv)
        HXTextView dateTv;

        public NoticeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            final Notice notice = dataList.get(position);
            titleTv.setText(notice.getTitle());
            contactsTv.setText(notice.getCreateByName());
            if(notice.getPicList() != null && notice.getPicList().size() > 0){
                Glide.with(context)
                        .load(notice.getPicList().get(0))
                        .error(R.mipmap.icon_head_potrait_o)
                        .placeholder(R.mipmap.icon_head_potrait_o)
                        .into(headPortraitImg);
            }
            dateTv.setText(notice.getCreateTime());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(notice);
                }
            });
        }
    }
}
